﻿using System;
using Web.App.Infrastructure.Localization.Contract;

namespace Webshop20.Presentation
{
    public abstract class PresentationModelBase
    {
        private const string APP_NAME = "shopping247.de";
        protected string viewName;
        protected string viewDescription;
        protected ILocalisationService localisationService;
        protected IPresentationState state;

        protected PresentationModelBase(ILocalisationService localisationService, IPresentationState state)
        {
            this.localisationService = localisationService;
            this.state = state;
        }

        protected PresentationModelBase(ILocalisationService localisationService)
        {
            this.localisationService = localisationService;
        }

        public virtual string Title
        {
            get
            {
                if (string.IsNullOrEmpty(viewName))
                    viewName = localisationService.GetText(GetType().Name + "_TITLE");

                return string.Format("{0} - {1}",viewName,APP_NAME);
            }
        }

        public virtual string Description
        { 
            get
            {
                if (string.IsNullOrEmpty(viewDescription))
                    viewDescription = localisationService.GetText(GetType().Name + "_DESCRIPTION");
                return viewDescription;
            }
        }

        public bool IsAuthenticated
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        protected string GetValueFromState(string key)
        {
            return state[key] != null ? state[key].ToString() : string.Empty; 
        }

        protected void SaveState(string key, string value)
        {
            state[key] = value;
        }
    }
}
